package com.atming.zuul.config;

import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.BlockResponse;
import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackProvider;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;


/**
 * 自定义限流处理
 */
@Slf4j
public class MyBlockFallbackProvider implements ZuulBlockFallbackProvider {


    @Override
    public String getRoute() {
        return "order-service";
    }

    @Override
    public BlockResponse fallbackResponse(String route, Throwable cause) {
        log.info(String.format("Sentinel block start..."));

        if(cause instanceof BlockException){
            return new BlockResponse(42900,"Sentinel block exception 定制化", route);
        }else{
            return new BlockResponse(500, "System Error", route);
        }

    }
}
